var host = window.location.hostname;
    host = 'http://' + host + '/soi.com/';
var loading ="<img src='" +  host + 'images/loading.gif' + "'/>";
function searchCategory(id, page){
    $("#content").html(loading);
    $.ajax({
        url:host+"video/searchcategory/"+id + '/'+page,
        success:function(res){
            $("#content").html(res);
        }}
    );
}
function search(){
    var value=$("#mod_search_searchword").val();
    if(value=="Searching..."){$("#mod_search_searchword").focus();return false;}
    $("#content").html(loading);
    var cbx=$("#cbx_cate").val();
    if($("#video-radio").is(':checked')){
        $.ajax({
            url:host + "video/search/" + cbx + '/1',
            data:"value=" + value,
            success:function(res){
                $("#content").html(res);
            }
        });
    }
    else searchActor(cbx, value, 1); return false;
}
function search2(value, page){
    $("#content").html(loading);
    var cbx=$("#cbx_cate").val();
    $.ajax({
        url: host + 'video/search/' + cbx + '/' + page,
        data:'value=' + value,
        success:function(res){
            $("#content").html(res);
        }
    });
}

function searchActor(catid, value, page){
    $("#content").html(loading);
    var cbx = catid;
    if(value == '') value=$("#mod_search_searchword").val();

    $.ajax({
        url: host + 'video/searchactor/' + cbx + '/' + page,
        data:'value=' + value,
        success:function(res){
            $("#content").html(res);
        },
        error:function(){alert('error!!');}
    });

    //var url = host + 'movie/searchactor/' + cbx + '/' + page;
    //var res = $.get(url, {value:value});
}
function starRating(id, vote){
    var rating = "<div id=\"mystar-rating\"> " +
            "<li class=\"current-rating\" style=\"width:" + vote * 15 + "px\"></li></div>";
    $.ajax({
        url:host + 'video/starrating/' + id + '/' + vote,
        success:function(res){
            $("#star-rating").html(rating);
            $("#rating_thanks").html('Thanks for rating');
        }
    });
}

function mostViews(page){$("#most_review .loading").html(loading); $("#most_review").load(host+'video/mostviews/'+page);}
function latest(page){$("#latest_review .loading").html(loading); $("#latest_review").load(host+'video/latestmovie/'+page);}
function topRate(page){$("#top_movies .loading").html(loading); $("#top_movies").load(host+'video/toprate/'+page);}
function calcHeight(iframeID){document.getElementById(iframeID).height=document.getElementById(iframeID).contentWindow.document.body.scrollHeight;}
//$(document).ready(function(){$("#pos1").load(host+'video/toprate/1/content.html');$("#pos2").load(host+'video/mostviews/1/content.html');$("#pos3").load(host+'video/latestmovie/1/content.html');});

//v_comment
 function checkComment(){
     temp=$("#editor-comment").val.replace(/ /gi, '');
     if(temp == '' || $("#editor-comment").val==''||$("#editor-comment").val=='Mời bạn viết nhận xét'){
         $("#editor-comment").focus();
     }
        temp=document.getElementById('name').value.replace(/ /gi, '');
        if(temp==''||document.getElementById('name').value=="Tên của bạn"){
            document.getElementById('mess').innerHTML='Hãy nhập tên';
            document.getElementById('name').innerHTML=temp;
            document.getElementById('name').focus();
            return false;
        }
        if(!check_email('email', 'mess')) return false;
        return true;
    }
    function check_email(email_id,err_id){
        emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;
        var err_mail='Email không đúng!!';
        if(emailRegExp.test(document.getElementById(email_id).value)) return true;
        else{
            document.getElementById(err_id).innerHTML=err_mail;
            document.getElementById(email_id).focus();
            return false;
        }
    }
    function insert(element, code){
        element = document.getElementById(element);
        if (document.selection){
            element.focus();
            sel = document.selection.createRange();
            sel.text = sel.text;
        }
        else if (element.selectionStart || element.selectionStart == '0'){
            element.focus();
            var startPos = element.selectionStart;
            var endPos = element.selectionEnd;
            element.value = element.value.substring(0, startPos) + code+ element.	value.substring(endPos,
                    element.value.length);
        }
        else{
            element.value += code;
        }
    }
    $(document).ready(function(){
        $("#cm-motion").hide('fast');
        $("#more-smiles").click(function(){
            $("#cm-motion").toggle('slow');
        });
        $("input[name=comment-submit]").click(function(){
            //disable submit button
            $("#comment-submit").attr('disable', 'disable');
            if(!checkComment()) return false;
            $("#cm-content .loading").html(loading);
            $.ajax({
                type: 'POST',
                url: host+"<?php echo 'comment/video/'.$movie_id.'/addnew.html'; ?>",
                data:'submit=1&email='+$("#email").val()+'&name='+$("#name").val()+'&comment='+$("#editor-comment")
                        .val(),
                success:function(data){
                    var name = $("#name").val();
                    var temp = "<div class=\"cm_info\">"+
                                    "<div class=\"cm_img\"><img src=\""+host+"images/no-ava.png\"/></div>"+
                                    "<div class=\"cm_detail\">"+
                                        "<div class=\"top\">"+
                                            "<span class=\"tcm_tt\"><i>"+name+"</i></span>"+
                                            "<span style=\"color: #555;font-size: 10px;\">1 phút trước</span>"+
                                        "</div>"+
                                        "<div class=\"content_cm\"><div>"+data+"</div></div>"+
                                        "<div class=\"bottom\"><img src=\""+host+"images/bottom.gif\"></div>"+
                                    "</div>"+
                                "</div>";
                    $("#cm-contents").prepend(temp);
                    $("#email").val('');
                    $("#name").val('');
                    $("#editor-comment").val('');
                    //enable submit button
                    $("#cm-content .loading").html('');
                    $("#mess").html('');
                    $("#comment-submit").attr('disable', '');
                    return false;
                }
            });
            return false;
        });
    });


//comment
$(document).ready(function(){
                $("#cm-contents").load(baseurl+"comment/video/<?php echo $movie_id; ?>/comment.html");
            });
            function viewComment(page){
                $("#cm-contents").load(baseurl+"comment/video/<?php echo $movie_id; ?>/"+page+"/comment.html");
            }